﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class WorkHourController : Controller
    {
        private ManHourManagerContext db = new ManHourManagerContext();

        //
        // GET: /WorkHour/

        public ActionResult Index()
        {
            var workhours = db.WorkHours.Include(w => w.Member);
            return View(workhours.ToList());
        }

        //
        // GET: /WorkHour/Details/5

        public ActionResult Details(int id = 0)
        {
            WorkHour workhour = db.WorkHours.Find(id);
            if (workhour == null)
            {
                return HttpNotFound();
            }
            return View(workhour);
        }

        //
        // GET: /WorkHour/Create

        public ActionResult Create()
        {
            ViewBag.MemberID = new SelectList(db.Members, "MemberID", "MemberName");
            return View();
        }

        //
        // POST: /WorkHour/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(WorkHour workhour)
        {
            if (ModelState.IsValid)
            {
                db.WorkHours.Add(workhour);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.MemberID = new SelectList(db.Members, "MemberID", "MemberName", workhour.MemberID);
            return View(workhour);
        }

        //
        // GET: /WorkHour/Edit/5

        public ActionResult Edit(int id = 0)
        {
            WorkHour workhour = db.WorkHours.Find(id);
            if (workhour == null)
            {
                return HttpNotFound();
            }
            ViewBag.MemberID = new SelectList(db.Members, "MemberID", "MemberName", workhour.MemberID);
            return View(workhour);
        }

        //
        // POST: /WorkHour/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(WorkHour workhour)
        {
            if (ModelState.IsValid)
            {
                db.Entry(workhour).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.MemberID = new SelectList(db.Members, "MemberID", "MemberName", workhour.MemberID);
            return View(workhour);
        }

        //
        // GET: /WorkHour/Delete/5

        public ActionResult Delete(int id = 0)
        {
            WorkHour workhour = db.WorkHours.Find(id);
            if (workhour == null)
            {
                return HttpNotFound();
            }
            return View(workhour);
        }

        //
        // POST: /WorkHour/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            WorkHour workhour = db.WorkHours.Find(id);
            db.WorkHours.Remove(workhour);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}